<?php

namespace App\Kuafu\Order\Exceptions;

use App\Exceptions\BaseException;
use App\Kuafu\Order\Enum\CodeEnum;
use App\Kuafu\Order\Enum\OrderCodeEnum;
use App\Kuafu\Order\Service\OrderBaseSplitService;
use App\Kuafu\Order\Service\OrderHandleService;

class OrderException extends BaseException
{
    /**
     * 判断订单是否是待支付
     *
     * @param OrderHandleService $order
     * @throws OrderException
     */
    public static function checkOrderStatus(OrderBaseSplitService $order)
    {
        if (!empty($order->getOrderInfo()) && !in_array($order->getOrderInfo()->payStatus, [
                CodeEnum::ORDER_PAY_STATUS_WAIT,
                CodeEnum::ORDER_PAY_STATUS_REVERSE,
            ])
        ) {
            $payStatus = CodeEnum::ORDER_PAY_STATUSES[$order->getOrderInfo()->payStatus] ?? '';
            throw new OrderException(OrderCodeEnum::ERR_ORDER_PAY_ERROR_STATUS,
                '订单支付状态为：' . $payStatus . '，不能下单支付。');
        }
    }
}
